# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.exporters import JsonLinesItemExporter

class FangPipeline(object):
    def __init__(self):
        self.fp1 = open('newhouse.json','wb')
        self.exproter1 = JsonLinesItemExporter(self.fp1,ensure_ascii=False,encoding='utf-8')
        self.fp2 = open('esf.json','wb')
        self.exproter2 = JsonLinesItemExporter(self.fp2,ensure_ascii=False,encoding='utf-8')

    def process_item(self, item, spider):
        if item.get('title'):
            self.exproter2.export_item(item)
        else:
            self.exproter1.export_item(item)

        return item

    def close_spider(self, spider):
        self.fp1.close()
        self.fp2.close()
        print('爬虫结束')
